import { GraphModel, NodeConfig, HtmlNode, HtmlNodeModel } from '@logicflow/core';
import { getBpmnId } from '../getBpmnId';
import './gateways.scss';
class ExclusiveGatewayModel extends HtmlNodeModel {
  static extendKey = 'ExclusiveGatewayModel';
  constructor(data:NodeConfig, graphModel:GraphModel) {
    if (!data.id) {
      data.id = `Gateway_${getBpmnId()}`;
    }
    if (!data.text) {
      data.text = '';
    }
    if (data.text && typeof data.text === 'string') {
      data.text = {
        value: data.text,
        x: data.x,
        y: data.y + 45,
      };
    }
    super(data, graphModel);
  }
  setAttributes(): void {
    this.width = 70;
    this.height = 70;
  }
}

class ExclusiveGatewayView extends HtmlNode {
  static extendKey = 'ExclusiveGatewayNode';
  setHtml(rootEl: HTMLElement) {
    const { properties } = this.props.model;
    const el = document.createElement('div');
    el.className = 'gateway-wrapper';
    if(properties.completed === 'true') {
			el.className = 'gateway-wrapper completed';
		}
    const html = `
      <div class="gateway-box">
        <svg viewBox="0 0 1024 1024" width="16" height="16"><path d="M469.333333 469.333333V170.666667h85.333334v298.666666h298.666666v85.333334h-298.666666v298.666666h-85.333334v-298.666666H170.666667v-85.333334h298.666666z" fill="#ffffff" p-id="6452"></path></svg>
      </div>
    `
    el.innerHTML = html;
    // 需要先把之前渲染的子节点清除掉。
    rootEl.innerHTML = '';
    rootEl.appendChild(el);
  }
}

const ExclusiveGateway = {
  type: 'bpmn2:exclusiveGateway',
  view: ExclusiveGatewayView,
  model: ExclusiveGatewayModel,
};

export { ExclusiveGatewayView, ExclusiveGatewayModel };
export default ExclusiveGateway;
